package IO;

import java.io.*;

public class IOZuoye {
	private void appendAToB(String path1, String path2){
		try {
			
			BufferedInputStream input = new BufferedInputStream(new FileInputStream(path1));
			BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(path2,true));//将f1追加到f2上
			byte[] buf = new byte[4049];
			int len;
			while((len=input.read(buf))!=-1)
				output.write(buf, 0, len);
			input.close();
			output.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch(IOException eIO){
			eIO.printStackTrace();
		}
	}
	private void appendABToC(String path1,String path2,String path3){
		try {
			
			BufferedInputStream input1 = new BufferedInputStream(new FileInputStream(path1));
			BufferedInputStream input2 = new BufferedInputStream(new FileInputStream(path2));
			BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(path3,true));
			byte[] buf = new byte[4049];
			int len;
			while((len=input1.read(buf))!=-1)
				output.write(buf, 0, len);
			while((len=input2.read(buf))!=-1)
				output.write(buf, 0, len);
			input1.close();
			input2.close();
			output.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch(IOException eIO){
			eIO.printStackTrace();
		}
	}
	public static void main(String[] args) {
		IOZuoye zuoye = new IOZuoye();
		zuoye.appendAToB("F:\\A.txt", "F:\\B.txt");
		zuoye.appendABToC("F:\\A.txt", "F:\\B.txt","F:\\C.txt");
	}

}
